<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="com.is.model.CourseScore"%>
<%@page import="com.is.control.CourseScoreControl"%>
<%@page import="com.is.control.ParamClassControl"%>
<%@page import="com.is.control.CourseClassControl"%>
<%@page import="com.is.model.CourseClass"%>
<%@page import="com.is.model.User"%>
<%@page import="com.is.control.StudentControl"%>
<%@page import="com.is.model.Student"%>
<%@page import="java.util.List"%>
<%@page import="com.is.util.Common"%>
<%@page import="com.is.control.ParamCourseControl"%>
<%@page import="com.is.util.ParamUtil"%>
<%@page import="com.is.control.ParamStuyearControl"%>
<%@page import="com.is.model.ParamCourseScoreGS"%>
<%@page import="com.is.control.ParamCourseScoreGSControl"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="/InterStu/resources/image/favicon.ico" />
<link rel="stylesheet" type="text/css" href="../../resources/css/all.css" />
<script type="text/javascript" src="../../resources/js/jquery-1.8.1.js"></script>
<link href="../../resources/css/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../../resources/js/jquery.artDialog.js"></script>
<script type="text/javascript" src="../../resources/js/iframeTools.js"></script>
<script type="text/javascript">
	$(function(){
		var block = $("#magic_block");
		if($(".active a").position()){
			block.css("top",$(".active a").position().top+10)
			.data("oriTop",$(".active a").position().top)
		}
		$(".nav ul li").find("a").hover(
			function(){
				var $this = $(this);
				var newTop = $this.position().top;
				block.stop().animate({
					top:newTop+10
				})
			},
			function(){
				block.stop().animate({
					top:block.data("oriTop")+10
				})
			}
		)
		
		var h = $(".right").height();
		$(".left").height(h);
		$(".update").click(function(){
			$.dialog.open("/InterStu/update_info.jsp",{width:460,height:400,title:"个人信息"});
		})
		$("[name='gradeScore']").click(function(){
			$.dialog.open("allCourseScoreOneClass.jsp",{width:620,title:"班级成绩"});
		})
		$("#course_scroe_gs").hide();
		$(".update_gs").click(function(){
			$.dialog({
				cancel: true,
				cancelVal: "关闭",
				title:"查看公式",
				content:document.getElementById("course_scroe_gs")
			})
		})
		$('img').error(function(){
			this.src = "/InterStu/resources/image/man.GIF";
		})
		/*公式*/
		var reg = /^\d+\.?\d*$/;
		var reg2 = /^0\d$/;
		$(".expression").bind("keyup",function(e){
			var currentSum = 0;
			for(var i = 0,j=0;i<$(".expression").size();i++){
				if($(".expression").eq(i).val() != ""){
					currentSum += $(".expression").eq(i).val()*1;
					j++;
				}
			}
			if(j == 4 && currentSum !=100){
				var temVal = $(this).val();
				$(".expression").val("");
				$(this).val(temVal);
			}
			currentSum-=$(this).val()*1;
			if(!reg.test($(this).val()) || $(this).val()*1 + currentSum >100){
				var tem = $(this).val().substring(0,$(this).val().length-1)
				$(this).val(tem);
			}
			if(($(this).val()+"").length<2 && $(this).val()!= "" && $(this).val()*1 === 0 && e.keyCode!=8 || $(this).val()== "."){
				 $(this).val("0.");
			}
		})
		.blur(function(){
			if($(this).val() != "" && $(this).val()*1 == 0){
				$(this).val("0.0");
			}
			var sum = 0;
			var j = 0;
			for(var i = 0;i<$(".expression").size();i++){
				if($(".expression").eq(i).val() != ""){
					j++;
					sum += $(".expression").eq(i).val()*1;
				}
			}
			if(j>2){
				for(var i = 0;i<$(".expression").size();i++){
					if($(".expression").eq(i).val() == "")
					$(".expression").eq(i).val(100 - sum);
				}
			}
		})
		$(".reset").click(function(e){
			$(".expression").val("");
		})
		$("[name='update_gs']").submit(function(e){
			var currentSum = 0;
			for(var i = 0;i<$(".expression").size();i++){
				if($(".expression").eq(i).val() != ""){
					currentSum += $(".expression").eq(i).val()*1;
				}
			}
			if(currentSum != 100){
				e.preventDefault();
			}
		})
		//alert(gs.msg1)
		$(".score").bind("input",function(){
			var msg = $(this).attr("alt");		
			if(!reg.test($(this).val()) || $(this).val()*1 >100){
				var tem = $(this).val().substring(0,$(this).val().length-1)
				$(this).val(tem);
			}
			if(reg2.test($(this).val())){
				$(this).val("0");
			}
		})
		/*submit*/
		$("[name='submit_score']").submit(function(e){
			if($(".score").val() == ""){
				e.preventDefault();
			}
		})
		/*求总成绩*/
		/*kongzhishuru*/
		var gs = {
			msg1:$("[name='cq']").val()*1,
			msg2:$("[name='daily']").val()*1,
			msg3:$("[name='midterm']").val()*1,
			msg4:$("[name='final']").val()*1
		};
		$(".finalScore").bind("input focus",function(){
			var fv = $(this).parent().prev().children().val()*1;
			var mv = $(this).parent().prev().prev().children().val()*1;
			var dv = $(this).parent().prev().prev().prev().children().val()*1;
			var lv = $(this).parent().prev().prev().prev().prev().children().val()*1;
			var fi = (fv*gs.msg4 + mv*gs.msg3 + dv*gs.msg2 + lv*100)/100;
			fi+="";
			fi=fi.length>4?fi.substring(0,5):fi;
			$(this).val(fi);
		})
		$(".finalScore").each(function(i){
			var fv = $(this).parent().prev().children().val()*1;
			var mv = $(this).parent().prev().prev().children().val()*1;
			var dv = $(this).parent().prev().prev().prev().children().val()*1;
			var lv = $(this).parent().prev().prev().prev().prev().children().val()*1;
			var fi = (fv*gs.msg4 + mv*gs.msg3 + dv*gs.msg2 + lv*100)/100;
			fi+="";
			fi=fi.length>4?fi.substring(0,4):fi;
			$(this).val(fi);
		})	
		setInterval(function(){
			$(".finalScore").each(function(i){
				var fv = $(this).parent().prev().children().val()*1;
				var mv = $(this).parent().prev().prev().children().val()*1;
				var dv = $(this).parent().prev().prev().prev().children().val()*1;
				var lv = $(this).parent().prev().prev().prev().prev().children().val()*1;
				var fi = (fv*gs.msg4 + mv*gs.msg3 + dv*gs.msg2 + lv*100)/100;
				fi+="";
				fi=fi.length>4?fi.substring(0,5):fi;
				$(this).val(fi);
			})
		},1000);
		
		if($("[name='checkScore0']").val() != $(".finalScore").eq(0).val() &&$("[name='checkScore0']").val() !=""){
			//alert($("[name='checkScore0']").val() +"dd"+ $(".finalScore").eq(0).val())
			artDialog.notice = function (options) {
		    var opt = options || {},
		        api, aConfig, hide, wrap, top,
		        duration = 800;
		        
		    var config = {
		        id: 'Notice',
		        left: '100%',
		        top: '100%',
		        fixed: true,
		        drag: false,
		        resize: false,
		        follow: null,
		        lock: false,
		        init: function(here){
		            api = this;
		            aConfig = api.config;
		            wrap = api.DOM.wrap;
		            top = parseInt(wrap[0].style.top);
		            hide = top + wrap[0].offsetHeight;
		            
		            wrap.css('top', hide + 'px')
		                .animate({top: top + 'px'}, duration, function () {
		                    opt.init && opt.init.call(api, here);
		                });
		        },
		        close: function(here){
		            wrap.animate({top: hide + 'px'}, duration, function () {
		                opt.close && opt.close.call(this, here);
		                aConfig.close = $.noop;
		                api.close();
		            });
		            
		            return false;
		        }
		    };	
		    
		    for (var i in opt) {
		        if (config[i] === undefined) config[i] = opt[i];
		    };
		    
		    return artDialog(config);
		};
		$.dialog.notice({
		    title: '提示信息',
		    width: 220,// 必须指定一个像素宽度值或者百分比，否则浏览器窗口改变可能导致artDialog收缩
		    content: '您已经修改了总成绩分布公式。请提交成绩，以保证数<br/>据完整性！',
		    icon: 'face-sad',
		    time: 10
		});
		}
	})
	
	
	 $(function(){
			$("input[name='go']").click(function(){
					document.forms['as'].action="score_go.jsp";
					document.forms['as'].submit();
			})
			$("input[name='ck']").click(function(){
					document.forms['as'].action="score_statistics.jsp";
					document.forms['as'].submit();
			})

       })
</script>
<title>留学生预科班</title>
<style type="text/css">
	#course_scroe_gs table{
		width:360px;
		margin:20px auto 30px;
		border:1px;
		border-collapse: collapse;
    	border-spacing: 0;
    	border-padding:0;
	}
	#course_scroe_gs table tr {height:40px;}
	#course_scroe_gs table tr td{border:1px solid #ccc;text-align:center; height:40px;}
</style>
</head>
<%
	//此页面需要的参数courseId
	User cu =(User)session.getAttribute("user"); 
	int stuyear=ParamStuyearControl.getCurrentStuyearId();  //此处需要改为自动获取当前学年
	int uid = (cu.getRole().equals("1"))?0:cu.getId();
	List<CourseClass> ccs = CourseClassControl.getAllCourseClassIdByUidAndStuyear(uid,stuyear);
	ccs = Common.sortCourseClassName(ccs);  //对班级+课程名排序
	int courseClassId = ParamUtil.getInt(request,"courseClassId",0);
	ParamCourseScoreGS scgs = ParamCourseScoreGSControl.getGSByCourseClassId(courseClassId);//该门课程对应的总分分配公式
	
%>
<body>
<div class="header">
	<div class="title pr">
    	<a href="javascript:void(0);"><span class="update pa">个人信息</span></a>
        <span class="logout pa"><a class="hide" href="/InterStu/login/logout.jsp">退出</a></span>
    </div>
</div>
<div class="main">
	<div class="left"> 
	   <div class="infomation">
			<div class="photo">
			<%
			String picUrl = cu.getPicUrl();
			%>
				<img width='60' height="60" src = "<%=picUrl %>" />
			</div>
			<div class="welcome">
				<%=cu.getName() %>,<br/>
				欢迎您使用！
			</div>
		</div>  	   	  	  	
    	<div class="nav">
        	<ul>	
        		<li class="pa" id="magic_block"></li>
        	<%if(cu!=null&&cu.getRole().equals("1")){ %>
                <li><a href="/InterStu/pages/stuyear/stuyear_start.jsp">新学期设置</a></li>
                
                <li><a href="/InterStu/pages/users/user_all.jsp">用户管理</a></li>
                <%} %>
                <li><a href="/InterStu/pages/students/student_add.jsp">学生管理</a></li>
                <li class="active"><a href="/InterStu/pages/dictation/dictation_add.jsp">学生考核</a></li>
                <%if(cu!=null&&cu.getRole().equals("1")){ %>
                <li><a href="/InterStu/pages/assess/teacher_assess.jsp">教职人员管理</a></li>
                <%} %>
            </ul>
        </div>
    </div>
    <div class="right">
    	<div class="r1">
    	<table class="dictations tab">
	    <tr>
	    	<td>
	    		<a href="/InterStu/pages/dictation/dictation_add.jsp">听写成绩</a>
			</td>
			<td>
				<a href="/InterStu/pages/homework/homework_add.jsp">作业成绩</a>			
			</td>
			<td>
				<a class="current" href="/InterStu/pages/courseScore/score_go.jsp">成绩录入</a>
			</td>
			 <%if(cu!=null&&cu.getRole().equals("1")){ %>
			<td>
				<a href="/InterStu/pages/evaluation/students_all.jsp">综合评价</a>
			</td>
			<%} %>
	    </tr>
	    </table>
    	 <form action="score_go.jsp" method="post" name="as">
    		<table class="table">
    			<caption>请选择</caption>
    			<tr>
    				<td width="25%">课程班级</td>
    				<td width="25%"><select name="courseClassId">
					<% 
					             for(CourseClass c:ccs){//可能一个任课老师有多个班级
					            	 %>
					            	 <option value="<%=c.getId() %>" <%=courseClassId==c.getId()?"selected":"" %>>
					            	 <%=ParamClassControl.getClassName(c.getClassId())%><%=ParamCourseControl.getCourseById(c.getCourseId()).getCourseName()  %></option> 
					            	 <%
					             }
					%>
					</select>
					</td>
    				<td width="25%"><input type="button" value="进入成绩录入" name="go"/></td>
    				<td><input type="button" value="查看成绩" name="ck"/></td>
    				<%if(cu.getRole().equals("1")){ %><td><input type="button" value="查看班级成绩" name="gradeScore"/></td><%} %>
    			</tr>
    		</table>
		</form>
        </div>
          <%
			   if(courseClassId!=0&&CourseClassControl.getCourseClassById(courseClassId)!=null){
			      CourseClass nowc = CourseClassControl.getCourseClassById(courseClassId);
			      ParamCourseScoreGS csgs = ParamCourseScoreGSControl.getGSByCourseClassId(courseClassId);
			 %>
			 
			<%
			     if(csgs==null){
			    	%>
			    	请先设置该课程总分的分配数值<a href=""></a>
			    	<%
			     }else{
			%>
        <div class="r2">
          
			<form name='submit_score' action="score_go_to.jsp" method="post">
			<table class='table'>
			<caption> 
			您当前记录的是<%=ParamCourseControl.getCourseById(nowc.getCourseId()).getCourseName() %>(<%=ParamCourseControl.getCourseById(nowc.getCourseId()).getCourseNameEn() %>)得分情况：
			<a href="javascript:void(0);" class="update_gs">(查看总成绩分布比例)</a>【<font color="red">在录入成绩前请确保出勤情况以及成绩公式本学期不再发生变化</font>】
			</caption>
			<thead>
				<tr>
				<th>姓名</th>
				<th>出勤成绩(满分<%=100*Double.parseDouble(csgs.getAttendance_per())/100 %>)</th>
				<th>平时成绩(占<%=100*Double.parseDouble(csgs.getDailyScore_per())/100 %>%)</th>
				<th>期中成绩(占<%=100*Double.parseDouble(csgs.getMiderScore_per())/100 %>%)</th>
				<th>期末成绩(占<%=100*Double.parseDouble(csgs.getFinalScore_per())/100 %>%)</th>
				<th>总成绩(满分100)</th>
				</tr>
			</thead>
			<tbody>
			<%
  		      List<Student> students = StudentControl.getAllStudentMulti("","","",String.valueOf(nowc.getClassId()),"","","","");
              int mark=0; 
			  for(Student s:students){
				  CourseScore cs = CourseScoreControl.getCSByStuIdAndCourseId(nowc.getId(),s.getId());
				  %>
					   <tr>
					   <td><%=s.getChineseName() %>(<%=s.getPassportName() %>)</td>
					   <td>
					   <%//要改的！！！！！！！！！！！！！！！！！！ %>
					   <input style="width:80px;" alt="msg1"  type="text" readonly="" class="score" name="attScore<%=mark %>" 
					   value="<%=CourseScoreControl.getAttendanceScoreByCCIDAndStuId(courseClassId,s.getId(),ParamStuyearControl.getCurrentStuyearId()) %>"/></td>
					   <td><input style="width:80px;" alt="msg2" type="text"  class="score" name="dailyScore<%=mark %>" value="<%=cs!=null?cs.getDailyScore():""%>"/></td>
					   <td><input style="width:80px;" alt="msg3" type="text" class="score" name="midtermScore<%=mark %>" value="<%=cs!=null?cs.getMidtermScore() :""%>"/></td>
					   <td><input style="width:80px;" alt="msg4" type="text" class="score" name="finalScore<%=mark %>" value="<%=cs!=null?cs.getFinalScore():""%>"/></td>
					   <td><input style="width:80px;" type="text" class="finalScore" name="totalScore<%=mark %>" value="<%=cs!=null?cs.getTotalScore():""%>" />
					   <input type="hidden" value="<%=s.getId() %>"  name="student<%=mark %>"/>
					   <input type="hidden" name="checkScore<%=mark %>" value="<%=cs!=null?cs.getTotalScore():""%>" />
					   </td>
					   </tr>
					   <%
	  			  mark++;
				 }
			 %>
			<tr>
			<td colspan="6">
				<input type="hidden" value="<%=students.size()%>" name="size"/>
				<input type="hidden" value="<%=nowc.getId()%>" name="courseClassId"/>
				<%
					if(CourseScoreControl.isInsertCourseScoreByStuyearAndCourseId(courseClassId, stuyear)){ 
						
				%>
				<% if(CourseClassControl.getCourseClassById(courseClassId).getState()==0) { %>
				<input type="submit" value="提交修改" />
				<%}else{
					out.print("<div align='center'><font color='red'>您已经提交成绩，如要修改，请联系管理员</font></div>");
				} %>
				<%}else{%>
					<input type="submit" value="提交成绩"/>
					<%
				} %>
			</td>
			</tr>
			</tbody>
			</table>
			</form>
			
			<%}}else{
				out.print("<div align='center'>请先选择要录入成绩的课程</div>");
			} %>
        </div>
    </div>
</div>
<% 
	ParamCourseScoreGS pcgs = ParamCourseScoreGSControl.getGSByCourseClassId(courseClassId);
	if(pcgs != null){
%>
<div id="course_scroe_gs">
	<form name="update_gs" action="update_coursescroe_gs.jsp?id=<%=courseClassId %>" method="post">
		<table>
			<caption>总成绩分布公式</caption>
			<tr>
				<td>出勤</td>
				<td>
				<input type="hidden" value="<%=courseClassId %>" name="courseClassId"/>
				<input type="text" class="expression" name="cq" value="<%=pcgs.getAttendance_per() %>"/></td>
			</tr>
			<tr>
				<td>平时</td>
				<td>
				<input type="text" class="expression" name="daily" value="<%=pcgs.getDailyScore_per() %>"/></td>
			</tr>
			<tr>
				<td>期中</td>
				<td><input type="text" class="expression" name="midterm" value="<%=pcgs.getMiderScore_per() %>"/></td>
			</tr>
			<tr>
				<td>期末</td>
				<td><input type="text" class="expression" name="final" value="<%=pcgs.getFinalScore_per() %>"/></td>
			</tr>
			<tr>
				<td colspan="2">
			<p>Tips:您若是要进行公式更改并且此前已经提交过成绩，请先联系管理员解除锁定后再进行公式更改。</p>
			</td></tr>
			<tr>
				<td colspan="2">
				<input type="button" class="reset" value="清空"/> &nbsp;&nbsp;&nbsp;
				<input type="submit" value="确定"/>
			</td>
			</tr>
		</table>
	</form>
</div>
<%} %>
<div class="footer">
	<p>版权所有：东北师范大学留学生预科部&nbsp;&nbsp;  蓝旭工作室开发</p>
</div>
</body>
</html>
